package com.lesso.lpq.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.lpq.sunflower.domain.repository.DeviceRepository;
import com.lesso.lpq.sunflower.infra.assembler.DeviceAssembler;
import com.lesso.lpq.sunflower.pojo.dto.DeviceDTO;
import com.lesso.lpq.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.lpq.sunflower.pojo.vo.DeviceVO;
import org.springframework.stereotype.Service;

/**
 * @ClassName : DeviceDomainService
 * @Description :
 * @Author : 罗培棋
 * @Date: 2025-07-05 09:59
 */
@Service
public class DeviceDomainService {
    private final DeviceRepository deviceRepository;

    public DeviceDomainService(DeviceRepository deviceRepository){
        this.deviceRepository = deviceRepository;
    }
    public Long save(DeviceDTO dto) {
        return deviceRepository.save(DeviceAssembler.INSTANCE.dtoToEntity(dto));
    }
    public Page<DeviceVO> page(DeviceQueryDTO dto) {
        return deviceRepository.getPageList(dto);
    }

    public Page<DeviceVO> customPage(DeviceQueryDTO dto) {
        return deviceRepository.getCustomPageList(dto);
    }

    public void deleteById(Long id) {
        deviceRepository.removeById(id);
    }

    public DeviceVO getByDeviceCode(String deviceCode) {
        return deviceRepository.getByDeviceCode(deviceCode);
    }
}
